using System;
using OFX.Aggregator.WebScraping.Infrastructure;

namespace OFX.Aggregator.WebScraping.Implementation.BESnet.HtmlPageProcessing
{
	public class BESnetAccountHomePageProcessor : IHtmlPageProcessor
	{
		public string Url { get; set; }

		#region Implementation of IHtmlPageProcessor

		public void TestAssumptions(IWebBrowser webBrowser)
		{
			IHtmlDocument document = webBrowser.Document;

			try
			{
				if (document.Frames.Count != 3)
					throw new AssumptionFailedException(this,
					                                    string.Format("Expected 3 IFRAMEs in page, found {0}.",
					                                                  document.Frames.Count));
			}
			catch (InvalidCastException e)
			{
				throw new AssumptionFailedException(this, "Element found was of different type than expected!", e);
			}
		}

		public void ProcessPage(IWebBrowser webBrowser, IHtmlPageProcessorFinished finished)
		{
			webBrowser.Navigate(this.Url);
		}

		#endregion
	}
}